package com.wngbms.netty._01simple.client;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

public class NettyClient {

    public static void main(String[] args) throws InterruptedException {

        EventLoopGroup group = new NioEventLoopGroup();

        try {
            // ServerBootstrap bootstrap = new ServerBootstrap();
            Bootstrap bootstrap = new Bootstrap();
            bootstrap = bootstrap.group(group);
            // NioServerSocketChannel.class
            Bootstrap channel = bootstrap.channel(NioSocketChannel.class);
            //
            Bootstrap handler = channel.handler(new ClientInitializerImpl());

            System.out.println("=====client ok=====");

            ChannelFuture channelFuture1 = bootstrap.connect("localhost", 8888);
            ChannelFuture sync = channelFuture1.sync();
            Channel channel1 = sync.channel();


            ChannelFuture channelFuture = channel1.closeFuture();
            System.out.println("1 "+channelFuture1);
            System.out.println("2 "+sync);
            System.out.println("3 "+channelFuture);
//            channelFuture.sync();

        } finally {
            group.shutdownGracefully();
        }

    }
}
